<template>
    <div>
        <h2>医生信息的添加</h2>
        <table class="table">
            <tbody>
                <tr>
                    <td>医生</td>
                    <td><input v-model="data.name" type="text"></td>
                </tr>
                <tr>
                    <td>科室</td>
                    <td>
                        <select v-model="data.kname" name="" id="">
                            <option value="">请选择</option>
                            <option v-for="i in ksdata" :value="i.name">{{ i.name }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>职称</td>
                    <td>
                        <select v-model="data.job" name="" id="">
                            <option value="">请选择</option>
                            <option value="主治医师">主治医师</option>
                            <option value="主任">主任</option>
                            <option value="普通医师">普通医师</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>学历</td>
                    <td>
                        <select v-model="data.xueli" name="" id="">
                            <option value="">请选择</option>
                            <option value="本科">本科</option>
                            <option value="研究生">研究生</option>
                            <option value="硕士">硕士</option>
                            <option value="博士">博士</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>第一执业医院</td>
                    <td><input v-model="data.yiyuan" type="text"></td>
                </tr>
                <tr>
                    <td>是否开通账号</td>
                    <td>
                        <input v-model="data.zhanghao" type="checkbox" name="" id="">已开通
                    </td>
                </tr>
                <tr>
                    <td>类型</td>
                    <td>
                        <select v-model="data.type" name="" id="">
                            <option value="">请选择</option>
                            <option value="本院医师">本院医师</option>
                            <option value="外院医师">外院医师</option>
                            <option value="其他">其他</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>创建时间</td>
                    <td>
                        <input v-model="data.createdate" type="date" name="" id="">
                    </td>
                </tr>
                <tr>
                    <td>照片</td>
                    <td>
                        <input @change="upfile" type="file" name="" id="">
                        <img style="width: 60px; height: 40px;" :src="'https://localhost:7260'+data.img" alt="">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const route= useRoute();
const router=useRouter();
const data=ref({
  "id": 0,
  "name": "",
  "kname": "",
  "job": "",
  "xueli": "",
  "img": "",
  "yiyuan": "",
  "type": "",
  "zhanghao": false,
  "createdate": "2025-02-18T09:46:18.051Z",
  "updatedate": "2025-02-18T09:46:18.051Z",
  "del": true
})
const ksdata=ref([{
    "id": 1,
    "name": "外科"
}])
onMounted(()=>{
    show();
})
const show=()=>{
    axios.get('https://localhost:7260/api/YiSheng/GetKeshis').then(res=>{
        ksdata.value=res.data
    })
}
const upfile=(i:any)=>{
    var f=i.target.files[0];
    var fd=new FormData();
    fd.append('file',f);
    //image/webp  image/jpeg image/png
    if(f.type!="image/webp"&&f.type!="image/jpeg"&&f.type!="image/png"){
        alert('上传的不是图片');
    }
    else{
        alert('上传的是图片');
    }
    if(f.size>2*1024*1024){
        alert('大小不能超过2MB');
        return;
    }
    axios.post('https://localhost:7260/api/YiSheng/Upfile',fd).then(res=>{
        data.value.img=res.data;
    })
}
const add=()=>{
    if(data.value.name==""){
        alert('名称不能为空');
        return;
    }
    axios.post('https://localhost:7260/api/YiSheng/AddYiSheng',data.value).then(res=>{
        if(res.data>0){
            alert('添加成功');
            router.push('/showys');
        }
        else{
            alert('失败');
        }
    })
}
</script>

<style scoped>

</style>